home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Applications / Mic-1 v1.0 / Project and Source / Source / mic_dump.cpp < prev    next >
Text File  |  1996-05-17  |  5KB  |  212 lines

  1. /*
  2.     "mic_dump.cpp"
  3.     
  4.     This file contains code for dumping the contents of the various objects of Mic-1
  5.     to the screen or to an arbitrary file.
  6. */
  7.  
  8. #include <iostream.h>
  9. #include <fstream.h>
  10.  
  11. #include "mic_main.h"
  12. #include "mic_dump.h"
  13. #include "mic_global_functions.h"
  14.  
  15. // constants for Dump()
  16. const short kFromDataPath = 0;
  17. const short kFromControl = 1;
  18. const short kFromMemory = 2;
  19. const short kFromEverything = 3;
  20.  
  21. const short kToDeathFile = 0;
  22. const short kToIndexedFile = 1;
  23. const short kToFinalFile = 2;
  24. const short kToScreen = 3;
  25.  
  26. // local prototypes
  27. short FindWhereToDump (void);
  28. void DumpSomething (Mic_1_Class& Mic, short whereFrom, ostream& dest);
  29.  
  30. void DumpDataPath (Mic_1_Class& Mic, ostream dest);
  31. void DumpControl (Mic_1_Class& Mic, ostream dest);
  32. void DumpMemory (Mic_1_Class& Mic, ostream dest);
  33. void DumpEverything (Mic_1_Class& Mic, ostream dest);
  34.  
  35. void doDump (Mic_1_Class& Mic)
  36. {
  37.     Boolean done = false;
  38.     short whereTo;
  39.     char c;
  40.     
  41.     cout << endl;
  42.     cout << "__DUMP___________________________________" << endl;
  43.     cout << " m - dump the main memory" << endl;
  44.     cout << " a - dump all (the whole processor)" << endl;
  45.     cout << " c - dump the control section" << endl;
  46.     cout << " d - dump the data path" << endl;
  47.     cout << " x - escape back to the previous menu" << endl;
  48.     cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
  49.     
  50.     while (!done)
  51.     {
  52.         cout << "dump >> ";
  53.         cin >> c;
  54.         switch (c)
  55.         {
  56.             case 'm': case 'M':
  57.                 whereTo = FindWhereToDump();
  58.                 Dump(Mic, kFromMemory, whereTo);
  59.                 done = true;
  60.                 break;
  61.             case 'a': case 'A':
  62.                 whereTo = FindWhereToDump();
  63.                 Dump(Mic, kFromEverything, whereTo);
  64.                 done = true;
  65.                 break;
  66.             case 'c': case 'C':
  67.                 whereTo = FindWhereToDump();
  68.                 Dump(Mic,kFromControl, whereTo);
  69.                 done = true;
  70.                 break;
  71.             case 'd': case 'D':
  72.                 whereTo = FindWhereToDump();
  73.                 Dump(Mic, kFromDataPath, whereTo);
  74.                 done = true;
  75.                 break;
  76.             case 'x': case 'X': done = true; break;
  77.             default: cout << "huh?" << endl; break;
  78.         }
  79.     }
  80.     
  81.     if ((c != 'x') && (whereTo != kToScreen))
  82.         cout << "Dump file written" << endl;
  83. }
  84.  
  85. short FindWhereToDump (void)
  86. {
  87.     char c = 0;
  88.     
  89.     while ((c != 's') && (c != 'f') && (c != 'S') && (c != 'F'))
  90.     {
  91.         cout << "Dump to the screen or to a file? (s/f) >> ";
  92.         cin >> c;
  93.     }
  94.     if ((c == 'f') || (c == 'F'))
  95.         return kToIndexedFile;
  96.     else //((c == 's') || (c == 'S'))
  97.         return kToScreen;
  98. }
  99.  
  100. // Dump - dump the contents of an object into any file or to the screen.
  101. //        I chose not to let the objects handle this because lots of code
  102. //        for the Dump function within each object would be repeated.
  103. void Dump (Mic_1_Class& Mic, const short whereFrom, const short whereTo)
  104. {
  105.     char fileName[32];
  106.     char *fileNamePtr;
  107.     Str32 tempString, tempString2;
  108.     StringPtr    tempStringPtr = tempString,
  109.                         tempString2Ptr = tempString2;
  110.     ofstream dumpfile;
  111.     
  112.     if (whereTo != kToScreen)
  113.     {
  114.         switch (whereFrom)
  115.         {
  116.             case kFromDataPath: GetIndString(tempStringPtr, 128, kFromDataPath + 3); break;
  117.             case kFromControl: GetIndString(tempStringPtr, 128, kFromControl + 3); break;
  118.             case kFromMemory: GetIndString(tempStringPtr, 128, kFromMemory + 3); break;
  119.             case kFromEverything: GetIndString(tempStringPtr, 128, kFromEverything + 3); break;
  120.         }
  121.         
  122.         switch (whereTo)
  123.         {
  124.             case kToDeathFile:
  125.                 GetIndString(tempStringPtr, 128, 1);
  126.                 NumToString(Data.Cycle, tempString2Ptr);
  127.                 Catenate(tempStringPtr, tempString2Ptr);
  128.                 break;
  129.             case kToIndexedFile:
  130.                 NumToString(Data.Cycle, tempString2Ptr);
  131.                 Catenate(tempStringPtr, tempString2Ptr);
  132.                 break;
  133.             case kToFinalFile:
  134.                 GetIndString(tempStringPtr, 128, 2);
  135.                 NumToString(Data.Cycle, tempString2Ptr);
  136.                 Catenate(tempStringPtr, tempString2Ptr);
  137.                 break;
  138.             default: break;
  139.         }
  140.         
  141.         fileNamePtr = fileName;
  142.         fileNamePtr = P2CStr(tempStringPtr);
  143.         dumpfile.open(fileNamePtr);
  144.         
  145.         DumpSomething(Mic, whereFrom, dumpfile);
  146.     }
  147.     else    // dump to screen, or cout
  148.     {
  149.         // nothing special to initialize here
  150.         cout << endl;
  151.         DumpSomething(Mic, whereFrom, cout);
  152.         cout << endl << endl;
  153.     }
  154.     
  155. }
  156.  
  157. void DumpSomething (Mic_1_Class& Mic, short whereFrom, ostream& dest)
  158. {
  159.     switch (whereFrom)
  160.     {
  161.         case kFromDataPath:
  162.             DumpDataPath(Mic, dest);
  163.             break;
  164.         case kFromControl:
  165.             DumpControl(Mic, dest);
  166.             break;
  167.         case kFromMemory:
  168.             DumpMemory(Mic, dest);
  169.             break;
  170.         case kFromEverything:
  171.             DumpEverything(Mic, dest);
  172.             break;
  173.     }
  174. }
  175.  
  176. void DumpDataPath (Mic_1_Class& Mic, ostream dest)
  177. {
  178.     dest << "***** Data Path Dump ***** Cycle " << Data.Cycle << " *****" << endl << endl;
  179.     dest << Mic.A_Latch << endl;
  180.     dest << Mic.B_Latch << endl;
  181.     dest << Mic.MBR << endl;
  182.     dest << Mic.MAR << endl;
  183.     dest << Mic.AMUX << endl;
  184.     dest << Mic.ALU << endl;
  185.     dest << Mic.Shifter << endl;
  186.     dest << Mic.ScratchPad << endl;
  187. }
  188.  
  189. void DumpControl (Mic_1_Class& Mic, ostream dest)
  190. {
  191.     dest << "***** Control Dump ***** Cycle " << Data.Cycle << " *****" << endl << endl;
  192.     dest << Mic.MMUX << endl;
  193.     dest << Mic.MPC << endl;
  194.     dest << Mic.MIR << endl;
  195. }
  196.  
  197. void DumpMemory (Mic_1_Class& Mic, ostream dest)
  198. {
  199.     dest << "***** Memory Dump ***** Cycle " << Data.Cycle << " *****" << endl << endl;
  200.     dest << Mic.Memory << endl;
  201. }
  202.  
  203. void DumpEverything (Mic_1_Class& Mic, ostream dest)
  204. {
  205.     dest << "***** Processor Dump ***** Cycle " << Data.Cycle << " *****";
  206.     dest << endl;
  207.     DumpControl(Mic, dest);
  208.     dest << endl;
  209.     DumpDataPath(Mic, dest);
  210.     dest << endl;
  211.     DumpMemory(Mic, dest);
  212. }